layui.use(['upload','layer'], function(){
    var upload = layui.upload
        ,layer = parent.layer === undefined ? layui.layer : top.layer
        ,$ = layui.jquery;
    var u = navigator.userAgent, app = navigator.appVersion;
    var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //android终端或者uc浏览器
    if(isAndroid){
        //$(":file").attr('capture','camera');
        //$(".takePhoto").attr('capture','camera');
        $(".choicePhoto").attr('capture','camera');
    }
    //执行实例
    upload.render({
        elem: '.choicePhoto'
        ,url: '/stuPhotoDr'
        //,data: {} //可选项。额外的参数，如：{id: 123, abc: 'xxx'}
        /*,accept: 'images' //允许上传的文件类型
        ,exts:'jpg|jpeg|bmp|png'*/
        ,multiple: true
        ,acceptMime: 'image/*'
        ,size: 10240 //最大允许上传的文件大小
        ,done: function(res,index,upload){
            console.log(res);
            console.log(res.msg);
            if('success' == res.msg){
                layer.msg("导入成功。");
                //location.href = "/index";
                location.href = "/toPhotoMake";
            }else if('error' == res.msg){
                layer.msg("导入失败。");
            }else{
                layer.msg(res.msg);
            }
        }
        ,error: function(){
            layer.msg("文件上传失败");
        }
    });

    $(".leftNav").click(function(){
        location.href="/index";
    });

    //PhotoMake
    $(".reset-photo").click(function(){
        location.href="/resetPhoto";
    });

    $(".admit-photo").click(function(){
        $.ajax({
            async: false,
            type: "POST",
            url: "/admitTempPhoto",
            data: "address="+$("#address").val(),
            success: function (data) {
                if('success' == data){
                    layer.msg("导入成功。");
                    location.href="/index";
                }else if('error' == data){
                    layer.msg("导入失败。");
                }else{
                    layer.msg(data);
                }
            },
            error:function(XMLHttpRequest, textStatus){
                console.log(XMLHttpRequest);
                console.log(textStatus);
                layer.msg("保存失败，请联系管理员。");
            }
        });
    });
});